Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add persistent improve #807

Merged
merged 1 commit into from
Mar 20, 2024
Merged

Add persistent improve #807

merged 1 commit into from
Mar 20, 2024

Conversation

mrT23
Copy link
Collaborator

@mrT23 mrT23 commented Mar 20, 2024

Type

enhancement, documentation


Description

  • Introduced a new feature to publish persistent comments for PR code suggestions, enhancing the review process by keeping the discussion in a single, updatable comment.
  • Updated documentation to reflect changes in default values and the addition of the persistent_comment option.
  • Updated configuration to include the persistent_comment option with a default value of false.

Changes walkthrough

Relevant files
Enhancement
pr_code_suggestions.py
Implement Persistent Comment Functionality                             

pr_agent/tools/pr_code_suggestions.py

  • Introduced persistent comment functionality for PR code suggestions.
  • Removed direct comment editing in favor of publishing persistent
    comments or editing existing ones based on settings.
  • Added logic to delete progress response after publishing a persistent
    comment.
  • +13/-3   
    Documentation
    improve.md
    Documentation Update for 'Improve' Tool Options                   

    docs/docs/tools/improve.md

  • Updated default values for num_code_suggestions, summarize, and
    num_code_suggestions_per_chunk.
  • Introduced persistent_comment option in the documentation with its
    default set to false.
  • +4/-3     
    Configuration changes
    configuration.toml
    Configuration Update for Persistent Comment                           

    pr_agent/settings/configuration.toml

    • Added persistent_comment setting with a default value of false.
    +1/-0     

    PR-Agent usage:
    Comment /help on the PR to get a list of all available PR-Agent tools and their descriptions

    … comment option, adjust default values, and enhance comment handling in pr_code_suggestions.py
    @codiumai-pr-agent-pro codiumai-pr-agent-pro bot added documentation Improvements or additions to documentation enhancement New feature or request labels Mar 20, 2024
    Copy link
    Contributor

    PR Description updated to latest commit (b702252)

    Copy link
    Contributor

    PR Review

    ⏱️ Estimated effort to review [1-5]

    2, because the changes are straightforward and well-documented, focusing on a single feature enhancement and its documentation.

    🏅 Score

    85

    🧪 Relevant tests

    No

    🔍 Possible issues

    Logic Flow: The deletion of the progress response is conditional on both the persistent_comment setting and the existence of a progress_response. This might lead to scenarios where progress responses are not deleted when expected, especially if the persistent_comment is disabled but a progress response exists.

    🔒 Security concerns

    No

    🔀 Multiple PR themes

    No


    ✨ Review tool usage guide:

    Overview:
    The review tool scans the PR code changes, and generates a PR review. The tool can be triggered automatically every time a new PR is opened, or can be invoked manually by commenting on any PR.
    When commenting, to edit configurations related to the review tool (pr_reviewer section), use the following template:

    /review --pr_reviewer.some_config1=... --pr_reviewer.some_config2=...
    

    With a configuration file, use the following template:

    [pr_reviewer]
    some_config1=...
    some_config2=...
    
    Utilizing extra instructions

    The review tool can be configured with extra instructions, which can be used to guide the model to a feedback tailored to the needs of your project.

    Be specific, clear, and concise in the instructions. With extra instructions, you are the prompter. Specify the relevant sub-tool, and the relevant aspects of the PR that you want to emphasize.

    Examples for extra instructions:

    [pr_reviewer] # /review #
    extra_instructions="""
    In the 'possible issues' section, emphasize the following:
    - Does the code logic cover relevant edge cases?
    - Is the code logic clear and easy to understand?
    - Is the code logic efficient?
    ...
    """
    

    Use triple quotes to write multi-line instructions. Use bullet points to make the instructions more readable.

    How to enable\disable automation
    • When you first install PR-Agent app, the default mode for the review tool is:
    pr_commands = ["/review", ...]
    

    meaning the review tool will run automatically on every PR, with the default configuration.
    Edit this field to enable/disable the tool, or to change the used configurations

    Auto-labels

    The review tool can auto-generate two specific types of labels for a PR:

    • a possible security issue label, that detects possible security issues (enable_review_labels_security flag)
    • a Review effort [1-5]: x label, where x is the estimated effort to review the PR (enable_review_labels_effort flag)
    Extra sub-tools

    The review tool provides a collection of possible feedbacks about a PR.
    It is recommended to review the possible options, and choose the ones relevant for your use case.
    Some of the feature that are disabled by default are quite useful, and should be considered for enabling. For example:
    require_score_review, require_soc2_ticket, require_can_be_split_review, and more.

    Auto-approve PRs

    By invoking:

    /review auto_approve
    

    The tool will automatically approve the PR, and add a comment with the approval.

    To ensure safety, the auto-approval feature is disabled by default. To enable auto-approval, you need to actively set in a pre-defined configuration file the following:

    [pr_reviewer]
    enable_auto_approval = true
    

    (this specific flag cannot be set with a command line argument, only in the configuration file, committed to the repository)

    You can also enable auto-approval only if the PR meets certain requirements, such as that the estimated_review_effort is equal or below a certain threshold, by adjusting the flag:

    [pr_reviewer]
    maximal_review_effort = 5
    
    More PR-Agent commands

    To invoke the PR-Agent, add a comment using one of the following commands:

    • /review: Request a review of your Pull Request.
    • /describe: Update the PR title and description based on the contents of the PR.
    • /improve [--extended]: Suggest code improvements. Extended mode provides a higher quality feedback.
    • /ask <QUESTION>: Ask a question about the PR.
    • /update_changelog: Update the changelog based on the PR's contents.
    • /add_docs 💎: Generate docstring for new components introduced in the PR.
    • /generate_labels 💎: Generate labels for the PR based on the PR's contents.
    • /analyze 💎: Automatically analyzes the PR, and presents changes walkthrough for each component.

    See the tools guide for more details.
    To list the possible configuration parameters, add a /config comment.

    See the review usage page for a comprehensive guide on using this tool.

    @Codium-ai Codium-ai deleted a comment from codiumai-pr-agent-pro bot Mar 20, 2024
    @mrT23 mrT23 merged commit 11502c5 into main Mar 20, 2024
    2 checks passed
    @mrT23 mrT23 deleted the tr/persistent_improve branch March 20, 2024 06:17
    @mrT23
    Copy link
    Collaborator Author

    mrT23 commented Mar 20, 2024

    /improve --pr_code_suggestions.persistent_comment=true

    @Codium-ai Codium-ai deleted a comment from codiumai-pr-agent-pro bot Mar 31, 2024
    @mrT23
    Copy link
    Collaborator Author

    mrT23 commented Mar 31, 2024

    PR Code Suggestions

    (Suggestions updated until commit b702252)

    CategorySuggestions                                                                                                                                                       
    Best practice
    Add error handling for publish_persistent_comment and edit_comment operations.

    Consider checking the success of the publish_persistent_comment and edit_comment
    operations. It's good practice to verify that these operations complete successfully, or
    to handle cases where they might fail, to ensure the robustness of your application.

    pr_agent/tools/pr_code_suggestions.py [122-131]

    -self.git_provider.publish_persistent_comment(pr_body,
    -                                             initial_header="## PR Code Suggestions
    
    ### (Suggestions updated until commit https://github.com/Codium-ai/pr-agent/commit/b70225294c0a178462c8b6b0004340524c498ec9)
    ",
    -                                             update_header=True,
    -                                             final_update_message=final_update_message, )
    -self.git_provider.edit_comment(self.progress_response, body=pr_body)
    +success = self.git_provider.publish_persistent_comment(pr_body,
    +                                                       initial_header="## PR Code Suggestions
    
    ### (Suggestions updated until commit https://github.com/Codium-ai/pr-agent/commit/b70225294c0a178462c8b6b0004340524c498ec9)
    ",
    +                                                       update_header=True,
    +                                                       final_update_message=final_update_message, )
    +if not success:
    +    # Handle failure case
    +success = self.git_provider.edit_comment(self.progress_response, body=pr_body)
    +if not success:
    +    # Handle failure case
     
    Documentation
    Update documentation to reflect the new default value for num_code_suggestions_per_chunk.

    Update the documentation to reflect the change in the default value of
    num_code_suggestions_per_chunk from 8 to 5, ensuring that users are aware of the new
    default settings.

    docs/docs/tools/improve.md [66]

    -- `num_code_suggestions_per_chunk`: number of code suggestions provided by the 'improve' tool, per chunk. Default is 5.
    +- `num_code_suggestions_per_chunk`: number of code suggestions provided by the 'improve' tool, per chunk. Default is 5. (Note: This default value has been updated from 8 to 5 in the latest version.)
     
    Add a comment explaining the persistent_comment configuration option.

    Since persistent_comment is a new feature, consider adding a comment in the configuration
    file explaining its purpose and effect. This will help users understand how to use this
    feature and its impact on the behavior of the tool.

    pr_agent/settings/configuration.toml [85]

    +# If set to true, enables the persistent comment feature, which updates the same comment for each new improvement request instead of creating a new one.
     persistent_comment=false
     
    Maintainability
    Use a more descriptive variable name for the update message control flag.

    Consider using a more descriptive variable name than final_update_message for the boolean
    flag controlling the update message behavior. A name like is_final_update might more
    clearly convey the purpose of the variable.

    pr_agent/tools/pr_code_suggestions.py [121]

    -final_update_message = False
    +is_final_update = False
     
    Refactor conditional logic to reduce nesting and improve readability.

    To improve code readability and maintainability, consider refactoring the conditional
    logic to reduce nesting. For example, you could handle the case where
    self.progress_response is not present first, and then proceed with the rest of the logic,
    reducing the need for deep nesting.

    pr_agent/tools/pr_code_suggestions.py [120-133]

    -if get_settings().pr_code_suggestions.persistent_comment:
    +if not self.progress_response:
    +    self.git_provider.publish_comment(pr_body)
    +elif get_settings().pr_code_suggestions.persistent_comment:
         final_update_message = False
         self.git_provider.publish_persistent_comment(pr_body,
                                                      initial_header="## PR Code Suggestions
    
    ### (Suggestions updated until commit https://github.com/Codium-ai/pr-agent/commit/b70225294c0a178462c8b6b0004340524c498ec9)
    ",
                                                      update_header=True,
    -                                                 final_update_message=final_update_message, )
    -    if self.progress_response:
    -        self.progress_response.delete()
    -    else:
    -        if self.progress_response:
    -            self.git_provider.edit_comment(self.progress_response, body=pr_body)
    -        else:
    -            self.git_provider.publish_comment(pr_body)
    +                                                 final_update_message=final_update_message)
    +    self.progress_response.delete()
    +else:
    +    self.git_provider.edit_comment(self.progress_response, body=pr_body)
     

    ✨ Improve tool usage guide:

    Overview:
    The improve tool scans the PR code changes, and automatically generates suggestions for improving the PR code. The tool can be triggered automatically every time a new PR is opened, or can be invoked manually by commenting on a PR.

    • When commenting, to edit configurations related to the improve tool (pr_code_suggestions section), use the following template:
    /improve --pr_code_suggestions.some_config1=... --pr_code_suggestions.some_config2=...
    
    [pr_code_suggestions]
    some_config1=...
    some_config2=...
    

    See the improve usage page for a comprehensive guide on using this tool.

    @mrT23 mrT23 added documentation Improvements or additions to documentation and removed documentation Improvements or additions to documentation labels Apr 2, 2024
    @mrT23
    Copy link
    Collaborator Author

    mrT23 commented Apr 2, 2024

    Title

    (Describe updated until commit b702252)

    Add persistent improve


    Type

    enhancement, documentation


    Description

    • Introduced support for persistent comments in PR code suggestions, allowing for a cleaner PR comment history.
    • Updated the 'improve' tool documentation to reflect new default values and the addition of the persistent_comment option.
    • Added persistent_comment to the configuration options with a default of false, enabling users to opt-in to persistent comments.

    Changes walkthrough

    Relevant files
    Enhancement
    pr_code_suggestions.py
    Support for Persistent Comments in PR Code Suggestions     

    pr_agent/tools/pr_code_suggestions.py

  • Added support for persistent comments in PR code suggestions.
  • Persistent comments are enabled through settings.
  • Progress response is deleted if persistent comments are enabled and
    progress response exists.
  • +13/-3   
    Documentation
    improve.md
    Documentation Update for 'Improve' Tool Configuration and Behavior

    docs/docs/tools/improve.md

  • Updated default values for num_code_suggestions, summarize, and
    num_code_suggestions_per_chunk.
  • Introduced persistent_comment option with a default of false.
  • Adjusted documentation to reflect changes in tool behavior and
    configuration options.
  • +4/-3     
    Configuration changes
    configuration.toml
    Configuration Option for Persistent Comments                         

    pr_agent/settings/configuration.toml

  • Added persistent_comment configuration option with a default value of
    false.
  • +1/-0     

    PR-Agent usage:
    Comment /help on the PR to get a list of all available PR-Agent tools and their descriptions

    @mrT23
    Copy link
    Collaborator Author

    mrT23 commented Apr 3, 2024

    PR Code Suggestions

    CategorySuggestions                                                                                                                                                       
    Maintainability
    Refactor comment handling to reduce code duplication.

    Consider using a single method to handle both persistent and non-persistent comments to
    reduce code duplication and improve maintainability. This method could accept parameters
    to determine the type of comment and the necessary actions.

    pr_agent/tools/pr_code_suggestions.py [120-133]

    -if get_settings().pr_code_suggestions.persistent_comment:
    -    final_update_message = False
    -    self.git_provider.publish_persistent_comment(pr_body,
    -                                                 initial_header="## PR Code Suggestions",
    -                                                 update_header=True,
    -                                                 final_update_message=final_update_message, )
    -    if self.progress_response:
    -        self.progress_response.delete()
    -else:
    -    if self.progress_response:
    -        self.git_provider.edit_comment(self.progress_response, body=pr_body)
    -    else:
    -        self.git_provider.publish_comment(pr_body)
    +self.handle_comment(pr_body, is_persistent=get_settings().pr_code_suggestions.persistent_comment)
     
    Enhancement
    Enhance documentation for the persistent_comment option.

    Clarify the behavior and implications of the persistent_comment option in the
    documentation, especially how it affects the visibility and tracking of improvements over
    time.

    docs/docs/tools/improve.md [60]

    -- `persistent_comment`: if set to true, the improve comment will be persistent, meaning that every new improve request will edit the previous one. Default is false.
    +- `persistent_comment`: if set to true, the improve comment will be persistent, meaning that every new improve request will edit the previous one, which can help in reducing clutter but may make tracking changes over time more difficult. Default is false.
     
    Best practice
    Add configuration validation for persistent_comment.

    Consider adding a configuration validation step to ensure that the persistent_comment
    setting is correctly configured (e.g., it should be a boolean). This can prevent runtime
    errors due to misconfiguration.

    pr_agent/settings/configuration.toml [85]

    +# Ensure this is a boolean value
     persistent_comment=false
     

    ✨ Improve tool usage guide:

    Overview:
    The improve tool scans the PR code changes, and automatically generates suggestions for improving the PR code. The tool can be triggered automatically every time a new PR is opened, or can be invoked manually by commenting on a PR.

    • When commenting, to edit configurations related to the improve tool (pr_code_suggestions section), use the following template:
    /improve --pr_code_suggestions.some_config1=... --pr_code_suggestions.some_config2=...
    
    [pr_code_suggestions]
    some_config1=...
    some_config2=...
    

    See the improve usage page for a comprehensive guide on using this tool.

    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    documentation Improvements or additions to documentation enhancement New feature or request Review effort [1-5]: 2
    Projects
    None yet
    Development

    Successfully merging this pull request may close these issues.

    1 participant